var n;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ADMgr = undefined;
var Const_Common = require("AA_Const_Common");
var GravityPlatform = require("AA_GravityPlatform");
var PlayerDataManager = require("AA_PlayerDataManager");
var GameConfig = require("AA_GameConfig");
var ArrayUtils = require("AA_ArrayUtils");
var CommonUtils = require("AA_CommonUtils");
var LoadingManager = require("AA_LoadingManager");
var LogManager = require("AA_LogManager");
var PlatformManager = require("AA_PlatformManager");
var SingletonManager = require("AA_SingletonManager");
var TipsManager = require("AA_TipsManager");
var _ = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t._adInstance = null;
    t._success_callback = null;
    t._fail_callback = null;
    t._retryCount = 0;
    t._maxRetry = 0;
    return t;
  }
  __extends(t, e);
  t.prototype.showRewardedVideo = function (e, t, o, n) {
    undefined === n && (n = 3);
    this.title = e;
    if (PlatformManager.PlatformMgr.isMiniGame() && !PlayerDataManager.PlayerDataMgr.WHITE_NAME_NO_VIDEO) {
      if (!GameConfig.default.adConfig.ADUnitId || 0 == GameConfig.default.adConfig.ADUnitId.length) {
        TipsManager.TipMgr.showToast("视频拉取失败");
        return void (o && o());
      }
      LoadingManager.LoadingMgr.show();
      this._success_callback = t;
      this._fail_callback = o;
      this._retryCount = 0;
      this._maxRetry = n;
      this._playRewardedVideo();
    } else {
      t && t();
    }
  };
  t.prototype._createRewardedVideoAd = function () {
    if (!this._adInstance) {
      var e = this._getADUnitId();
      this._adInstance = mg.createRewardedVideoAd({
        adUnitId: e
      });
      this._adInstance.onError(this._reward_error.bind(this));
      this._adInstance.onClose(this._reward_close.bind(this));
      this._adInstance.onLoad(this._reward_loaded.bind(this));
    }
    return this._adInstance;
  };
  t.prototype._playRewardedVideo = function () {
    var e = this._createRewardedVideoAd();
    e.load().then(function () {
      e.show();
    });
  };
  t.prototype._getADUnitId = function () {
    var e = GameConfig.default.adConfig.ADUnitId;
    return ArrayUtils.default.randomArrayOne(e);
  };
  t.prototype._reward_error = function (e) {
    if (this._retryCount < this._maxRetry) {
      this._retryCount++;
      this._playRewardedVideo();
    } else {
      TipsManager.TipMgr.showToast("视频加载失败，请稍后再试！");
      LoadingManager.LoadingMgr.hide();
      LogManager.LogMgr.debug("show reward video error: " + e);
    }
  };
  t.prototype._reward_close = function (e) {
    LoadingManager.LoadingMgr.hide();
    LogManager.LogMgr.debug("reward video close " + JSON.stringify(e));
    if (null == e ? undefined : e.isEnded) {
      this._success_callback && this._success_callback();
      CommonUtils.default.SendPoint(Const_Common.SendPointType.视频打点, this.title);
      GravityPlatform.default.GA_adShowEvent();
    } else {
      this._fail_callback && this._fail_callback();
    }
  };
  t.prototype._reward_loaded = function () {
    LogManager.LogMgr.debug("reward video load success");
  };
  return t;
}(SingletonManager.SingletonMgr);
exports.ADMgr = _.getInstance();